<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/common_css :: commonHeader('编辑类别')">
</head>
<link rel="stylesheet" th:href="@{/js/admin.ui/lib/zTree/v3/css/metroStyle/metroStyle.css}" type="text/css">
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-knowledge-type-edit">
        <input type="hidden" id="id" name="id" th:value="${e.id }" />

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>设备类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <select type="text" class="input-text" id="type" name="type">
                    <option th:value="1">视频设备</option>
                    <option th:value="2">虫情测报设备</option>
                </select>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <select type="text" class="input-text" id="state" name="state">
                    <option th:value="1">正常</option>
                    <option th:value="2">异常</option>
                </select>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <select type="text" class="input-text" id="equipmentId" name="equipmentId">
                    <th:block th:each="item:${e1}">
                        <option th:value="${item.id}" th:text="${item.name}"></option>
                    </th:block>
                </select>
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>数据阈值：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="数据阈值（必填）" th:value="${e.yz}" id="yz" name="yz" maxlength="50" onkeyup="value=value.replace(/[^\d]/g,'')" />
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">数据内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="content" id="content" maxlength="200" class="textarea"  placeholder="数据内容...200个字符以内" onKeyUp="javascript:textareaLength(this);"><th:block th:text="${e.content}"></th:block></textarea>
                <p class="textarea-numberbar"><em class="textarea-length"><span id="textareaLengthSpan">0</span></em>/200</p>
            </div>
        </div>

        <div class="row cl">
            <div style="text-align: center;">
                <button class="btn btn-primary radius" type="button" onclick="edit();">
                    <i class="Hui-iconfont">&#xe632;</i> 保存
                </button>
                &nbsp;&nbsp;
                <button onClick="layer_close();" class="btn btn-default radius" type="button">
                    &nbsp;&nbsp;取消&nbsp;&nbsp;
                </button>
            </div>
        </div>
    </form>
</article>
<div th:include="admin/common/common_js :: onLoadJS"></div>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/jquery.validation/1.14.0/jquery.validate.js}"></script>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/jquery.validation/1.14.0/validate-methods.js}"></script>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/jquery.validation/1.14.0/messages_zh.js}"></script>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js}"></script>
<script type="text/javascript" th:inline="javascript">

    $("#type").val([[${e.type}]]);
    $("#state").val([[${e.state}]]);
    $("#equipmentId").val([[${e.equipmentId}]]);



    function edit() {
        var yz = $("#yz").val();
        var content = $("#content").val();
        if(yz == ""){
            layer.msg('请输入阈值', {icon: 2});
            return false;
        }else if(content == ""){
            layer.msg('请输入数据内容', {icon: 2});
            return false;
        }
        send(
            "/pestdiagnosis/sys/pest/editEqData",
            $('#form-knowledge-type-edit').serialize(),
            function (data) {
                layer.msg(data.message, {icon: 1,time: 1500}, function() {
                    window.parent.location.href = "/pestdiagnosis/sys/pest/toListEqData";
                });
            },
            function (res) {
                layer.msg('网络异常，请稍后再试', {icon: 2});
            }
        );
    }
    // 计算文本域字符长度
    function textareaLength(obj) {
        $('#textareaLengthSpan').text($(obj).val().length);
    }
</script>
</body>
</html>